import { createApp } from 'vue'
import App from './App.vue'
import router from './route'
import store from './store'   //重要 重要 重要


import axios from 'axios'
axios.defaults.baseURL='http://apis.imooc.com/api/'
axios.interceptors.request.use(config=>{
    store.commit('setLoading',true)  //打开加载
    store.commit('setError',{status:false,message:''})  //重置以下数值
    config.params={...config.params,icode:'C6A6C4086133360B'}
    return config
},e=>{
    console.log(e.response)
    const {error}=e.response.data
    store.commit('setError',{status:true,message:error})
    store.commit('setLoading',false)
    return Promise.reject(error)  //return一个promise，调用方法之后then,获取error值
})
axios.interceptors.response.use(config=>{
    store.commit('setLoading',false) //关闭加载
    return config
})




// async function hello(){
//     return 'hello'
// }
async function hello() {
    const greeting=await Promise.resolve('hello')
    return greeting  //hello
}
// hello() 返回一个promise对象，有返回值，才能执行then
hello().then(value=>console.log(value))  //hello




createApp(App).use(router).use(store).mount('#app')
